package org.ytor.core.sysapi.sse.service.handler;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.ytor.core.sysapi.monitor.logic.SystemMonitorLogic;
import org.ytor.core.sysapi.sse.service.AbsSseEventHandler;
import org.ytor.core.sysapi.sse.service.support.DefaultSseRegister;

/**
 * created by yangtong on 2025/7/8 18:19:04
 * <br/>
 * SSE,获取实时系统负载
 */
@Component
@RequiredArgsConstructor
public class SseJvmRealtimeHandler extends AbsSseEventHandler {

    private final SystemMonitorLogic systemMonitorLogic;
    private final DefaultSseRegister sseRegister;

    public String cronExpression() {
        return "0/3 * * * * ?";
    }

    /**
     * 事件类型
     */
    public String getEventName() {
        return "SysMonitor-JvmRealtime";
    }

    public Object doExec() {
        if (sseRegister.size() > 0) {
            return systemMonitorLogic.jvmRealtime();
        }
        return null;
    }
}
